﻿Ext.define("PSI.BaseCode.Admin.Category.CategoryEditForm", {

    createUI: function () {

        var me = this;
        var Addbasecodewindow = Ext.create("Ext.window.Window", {
            title: "新增码表分类",
            modal: true,
            onEsc: Ext.emptyFn,
            width: 400,
            height: 100,
            border: false,
            layout: "fit",
            items: [
                 {
                     id: "editForm",
                     xtype: "form",
                     layout: "form",
                     height: "100%",
                     bodyPadding: 5,
                     defaultType: 'textfield',
                     fieldDefaults: {
                         labelWidth: 70,
                         labelAlign: "right",
                         labelSeparator: "",
                         msgTarget: 'side'
                     },
                     items: [
                           {
                               xtype: "hidden",
                               name: "categoryId",
                               value: null
                           },
                           {
                               id: "editName",
                               fieldLabel: "类别名称",
                               allowBlank: false,
                               blankText: "没有输入名称",
                               beforeLabelTextTpl: PSI.Const.REQUIRED,
                               name: "categoryName",
                               value: null
                           }
                     ],
                     buttons: [
                        {
                            text: "确定",
                            formBind: true,
                            iconCls: "psi-button-ok",
                            handler: this.onOK,
                            scope: this
                        },
                        {
                            text: "取消", handler: function () {
                                var me = this;
                                PSI.MsgBox.confirm("请确认是否取消操作?", function () {
                                    me.addbasecodewindow.close();
                                });
                            }, scope: this
                        }
                     ]
                 }

            ]

        }).show();
        me.addbasecodewindow = Addbasecodewindow;

    },

    show: function () {

        return this.createUI();

    },

    onOK: function () {
        var me = this;
        var category = Ext.getCmp("caregorytree");
        var win = this.addbasecodewindow
        var f = Ext.getCmp("editForm");
        var el = f.getEl();
        el.mask("数据保存中...");
        f.submit({
            url: "/BaseCodeAdminCategory/AddorEditBaseCodeCateGory",
            method: "POST",
            success: function (form, action) {
                debugger; el.unmask();
                var cc = action.result.success;
                if (cc) {
                    PSI.MsgBox.showInfo("数据保存成功", function () {
                        win.close();
                        var store = category.getStore();
                        store.load();
                    });
                }
                else {
                    Ext.Msg.alert('Failure', action.result.msg);
                }
            },
            failure: function (form, action) {
                el.unmask();
                switch (action.failureType) {
                    case Ext.form.action.Action.CLIENT_INVALID:
                        Ext.Msg.alert('Failure', 'Form fields may not be submitted with invalid values');
                        break;
                    case Ext.form.action.Action.CONNECT_FAILURE:
                        Ext.Msg.alert('Failure', 'ajax链接失败!');
                        break;
                    case Ext.form.action.Action.SERVER_INVALID:
                        Ext.Msg.alert('Failure', action.result.msg);
                }
            }
        });

    }
    
    
})